1656A - Good Pairs - CodeForces Solution


constructive algorithms math

Please click on ads to support us..

Python Code:

for t in range(int(input())):
    n = int(input())
    ar = list(map(int,input().split()))
    a = max(ar)
    b = min(ar)
    c = ar.index(a)+1
    d = ar.index(b)+1
    print(f"{c} {d}")

C++ Code:

#include<bits/stdc++.h>
#define ll long long
#define yes cout<<"YES\n";
#define no  cout<<"NO\n";
#define first F
#define second S
using namespace std;

int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL); // flushes cout
int t;
cin>>t;
int x,y,k;
while(t--){
    cin>>x;
    int a=0;
    vector<int>arr(x);
    for(int i=0;i<x;i++)
        cin>>arr[i];
    int k1=min_element(arr.begin(),arr.end())-arr.begin();
    int k2=max_element(arr.begin(),arr.end())-arr.begin();
    cout<<min(k1,k2)+1<<" "<<max(k1,k2)+1<<"\n";


}
}


Comments

Submit
0 Comments
More Questions

32. Longest Valid Parentheses
Cutting a material
Bubble Sort
Number of triangles
AND path in a binary tree
Factorial equations
Removal of vertices
Happy segments
Cyclic shifts
Zoos
Build a graph
Almost correct bracket sequence
Count of integers
Differences of the permutations
Doctor's Secret
Back to School
I am Easy
Teddy and Tweety
Partitioning binary strings
Special sets
Smallest chosen word
Going to office
Color the boxes
Missing numbers
Maximum sum
13 Reasons Why
Friend's Relationship
Health of a person
Divisibility
A. Movement